# Makefile for 104 Protocol Library
# 104协议库根目录Makefile

# 编译器设置
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -O2 -g
AR = ar
ARFLAGS = rcs

# 目录设置
BUILD_DIR = ../../output/104
OBJ_DIR = $(BUILD_DIR)/obj
LIB_DIR = $(BUILD_DIR)/lib
BIN_DIR = $(BUILD_DIR)/bin

# 协议类型（可通过环境变量设置）
PROTOCOL ?= 104

# 包含路径 - 使用根目录的通用模块
INCLUDES = -I../../common/utils/include -I../../common/version/include -I../../common/json/include -I../../common/config/include -I../../common/network/include -I../../common/logs/include -Icore/common/utils/include -Icore/common/types/include -Icore/common/error/include

# 库文件路径 - 使用根目录的通用库
LIBS = -L../../common -L$(LIB_DIR) -lcommon -lpthread

# 默认目标
all: directories core controller

# 创建目录
directories:
	@mkdir -p $(OBJ_DIR)
	@mkdir -p $(LIB_DIR)
	@mkdir -p $(BIN_DIR)

# 构建通用模块 - 使用根目录的通用模块
common:
	@echo "Building common modules..."
	cd ../../common && make all

# 构建104协议核心模块
core:
	@echo "Building 104 protocol core module..."
	cd core && make BUILD_VERSION=debug simple_output
	@echo "Core module completed"

# 构建104协议控制器
controller:
	@echo "Building 104 protocol controller..."
	cd controller && make all
	@echo "Controller completed"

# 安装
install: core controller
	@echo "Installing 104 protocol module..."
	cd controller && make install

# 清理
clean:
	@echo "Cleaning all modules..."
	cd ../../common && make clean
	cd core && make clean
	cd controller && make clean
	rm -rf $(BUILD_DIR)

# 帮助
help:
	@echo "Available targets:"
	@echo "  all         - Build all modules"
	@echo "  core        - Build core module only"
	@echo "  controller  - Build controller module only"
	@echo "  clean       - Clean all build files"
	@echo "  help        - Show this help"

.PHONY: all directories core controller clean help